package com.example.demo.service.impl;

import com.example.demo.entity.Employee;
import com.example.demo.mapper.EmployeeMapper;
import com.example.demo.service.EmployeeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeServiceImpl implements EmployeeService {

    Logger logger = LoggerFactory.getLogger(EmployeeServiceImpl.class);

    @Autowired
    private EmployeeMapper employeeMapper;


    @Override
    public Employee insert(Employee employee) {
        employeeMapper.insert(employee);
        return employee;
    }


    @Override
    public Employee update(Employee employee) {
        employeeMapper.update(employee);
        return employee;
    }

    /**
     * 不能service层调用，会导致redis不更新
     * @param xxId
     * @return
     */
    @CachePut(cacheNames = "employees",key = "#xxId")
    @Override
    public List<Employee> updateList(String xxId){
        return employeeMapper.getList();
    }

    @Cacheable(cacheNames = "employees",key = "#xxId")
    @Override
    public List<Employee> getList(String xxId) {
        logger.info("========从查询数据库中查询======xxId："+xxId);
        return employeeMapper.getList();
    }
}
